﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirstGade
{
    public class Mathvoid
    {
        const string SampleFileDataPath1 = "D:\\SampleFile1.data";
        private string s;
        public static int right = 0;                          //记录答对的总数！
        public static int wrong = 0;                          //记录答错的总数！

        public void mathjia()                                 //加法运算！
        {
            int a, b;
            int result;
            Random rd = new Random();                         //随机数
            a = rd.Next(0, 11);                               //0到11中取一个
            b = rd.Next(0, 11);
            s = "请计算：{" + a + "}+{" + b + "}=？";
            string s2 = "答案：" + a + b;
            Console.WriteLine("请计算：{0}+{1}=？", a, b);    //输出提示
            CreateSampleFileAsync(1500000, s, s2).Wait();//异步方式创建文件

            result = Convert.ToInt32(Console.ReadLine());     //输入值      
            if (result == a + b)
            {

                Console.WriteLine("回答正确！");
                right++;
            }
            else
            {
                Console.WriteLine("错误，继续努力！");
                wrong++;
            }
        }
        public void mathjian()                                //减法运算！
        {
            int a, b;
            int result;
            Random rd = new Random();
            a = rd.Next(0, 11);
            b = rd.Next(0, 11);
            Console.WriteLine("请计算：{0}-{1}=？", a, b);
            result = Convert.ToInt32(Console.ReadLine());
            if (result == a - b)
            {
                Console.WriteLine("回答正确！");
                right++;
            }
            else
            {
                Console.WriteLine("错误，继续努力！");
                wrong++;
            }
        }
        public void mathcheng()                               //乘法运算！
        {
            int a, b;
            int result;
            Random rd = new Random();
            a = rd.Next(0, 11);
            b = rd.Next(0, 11);
            Console.WriteLine("请计算：{0}*{1}=？", a, b);
            result = Convert.ToInt32(Console.ReadLine());
            if (result == a * b)
            {
                Console.WriteLine("回答正确！");
                right++;
            }
            else
            {
                Console.WriteLine("错误，继续努力！");
                wrong++;
            }

        }
        public void mathchu()                                 //除法运算！
        {
            int a, b;
            int result;
            Random rd = new Random();
            a = rd.Next(0, 11);
            b = rd.Next(0, 11);
            if (b != 0)
            {
                Console.WriteLine("请计算：{0}/{1}=？", a, b);
                result = Convert.ToInt32(Console.ReadLine());
                if (result == a / b)
                {
                    Console.WriteLine("回答正确！");
                    right++;
                }
                else
                {
                    Console.WriteLine("错误，继续努力！");
                    wrong++;
                }
            }
            else
            {
                if (a != 0)
                {
                    Console.WriteLine("请计算：{0}/{1}=？", b, a);
                    result = Convert.ToInt32(Console.ReadLine());
                    if (result == b / a)
                    {
                        Console.WriteLine("回答正确！");
                        right++;
                    }
                    else
                    {
                        Console.WriteLine("错误，继续努力！");
                        wrong++;
                    }
                }
            }
        }
        public void result()                                  //统计结果！
        {
            Console.WriteLine("总共做了{0}道题：你做对了{1}道题，做错了{2}道题。", right + wrong, right, wrong);
        }
        public static async Task CreateSampleFileAsync(int nRecords, string s, string s2)
        {
            using (FileStream stream = File.Create(SampleFileDataPath1))//File.Create创建文件//FileStream文件流类
            using (var writer = new StreamWriter(stream))
            {
                var r = new Random();
                var records = Enumerable.Range(1, nRecords);
                await writer.WriteAsync(s);
                await writer.WriteAsync(s2);

            }
        }
    }

}
